package com.hqyj.paimaisys.web;

import org.springframework.stereotype.Component;

import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;

@Component
@ServerEndpoint("/point1/{name}")
public class TestWebSocket {
     //四个方法

    public TestWebSocket(){
        System.out.println(this);
    }

    //Session 指客户端和服务端的会话对象
    @OnOpen
    public void open(@PathParam("name") String name, Session session) throws IOException {
        System.out.println("接收到客户端的连接，name ： " + name);
        session.getBasicRemote().sendText("你好：" + name);

    }

    @OnError
    public void error(Throwable e, Session session){
        System.out.println(" 出异常了 ");
    }

    @OnClose
    public void error(Session session){
        System.out.println(" 会话关闭了 ");
    }

    @OnMessage
    public void receivemsg(String msg, Session session){
        System.out.println(" 接收到了对方的消息 ");
    }

}
